package com.appspot.niehonglei.action;

import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminLogin implements ActionInterface {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		try {
			String logName = request.getParameter("logName");
			String password = request.getParameter("password");
			String url = request.getParameter("url");
			String param = "?";
			if (url != null && !"".equals(url.trim())) {
				param = "?url=" + URLEncoder.encode(url,"utf-8");
			}
			if ("niehonglei".equals(logName) && "sgst".equals(password)) {
				request.getSession().setAttribute("logName", logName);
				if(url!=null && !"".equals(url)){
					response.sendRedirect(url);
				} else {
					response.sendRedirect("/publish");
				}
			} else {
				response.sendRedirect("/login" + param + "&tip=" + URLEncoder.encode("用户名或密码不正确!","utf-8"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
